<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('流程定义')"/>
    <th:block th:include="include :: jasny-bootstrap-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>流程KEY：</p>
                            <input type="text" name="key"/>
                        </li>
                        <li>
                            <p>名称：</p>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <p>所属分类：</p>
                            <input type="text" name="category"/>
                        </li>
                        <!--<li class="select-time">
                            <label>部署时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                        </li>-->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <div id="processDefinitionDiv" class="fileinput fileinput-new" data-provides="fileinput"
                 style="margin-bottom: 0; margin-right: -3px;">
										<span class="btn btn-success btn-file" style="font-size: 12px;">
											<span><i class="fa fa-upload"></i> 部署流程定义</span>
											<input type="file" name="processDefinition" multiple>
										</span>
                <span class="fileinput-filename"></span>
                <a href="#" class="close fileinput-exists" data-dismiss="fileinput" style="float: none">&times;</a>
            </div>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:procdef:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:procdef:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-danger multiple disabled"
               shiro:hasPermission="system:procedef:remove">
                <i class="fa fa-image"></i> 查看
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>

<div th:include="include :: footer"></div>
<th:block th:include="include :: jasny-bootstrap-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('procdef:Procdef:edit')}]];
    var removeFlag = [[${@permission.hasPermi('procdef:Procdef:remove')}]];
    var prefix = ctx + "system/procdef";
    var datas = [[${@dict.getType('sys_normal_disable')}]];

    $(function () {
        var options = {
            url: prefix + "/list",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "流程定义",
            uniqueId: "deploymentId",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '流程ID'
                },
                {
                    field: 'key',
                    title: '流程KEY'
                },
                {
                    field: 'name',
                    title: '流程名称'
                },
                {
                    field: 'version',
                    title: '版本'
                },
                {
                    field: 'description',
                    title: '流程描述'
                },
                {
                    field: 'category',
                    title: '所属分类'
                },
                {
                    field: 'deploymentTime',
                    title: '部署时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.deploymentId + '\')"><i class="fa fa-remove"></i> 删除</a>');
                        actions.push('<a class="btn btn-success btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="showProcessImgDialog(\'' + row.deploymentId+ '\')"><i class="fa fa-image"></i> 查看</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        initProcessDefinitionFileInput();
    });

    function initProcessDefinitionFileInput() {
        $('#processDefinitionDiv').on('change.bs.fileinput', function (e) {
            // 处理自己的业务
            var formdata = new FormData();
            formdata.append("processDefinition", $('input[type=file]')[0].files[0]);
            $.ajax({
                url: prefix + '/upload',
                data: formdata,
                type: "post",
                processData: false,
                contentType: false,
                success: function (result) {
                    $('#processDefinitionDiv').fileinput('reset');     // 重置
                    $.operate.ajaxSuccess(result);
                }
            })
        });
    }

    function showProcessImgDialog(deploymentId) {
        var url = ctx + 'process/general/processDefinitionImage/' + deploymentId;
        $.modal.open("查看流程图", url);
    }
</script>
</body>
</html>
